using System;


namespace Commons.Geom
{
	[Serializable]
	public class Rectangle
	{
		public int x;
		public int y;
		public int width;
		public int height;

		public Rectangle (int x, int y, int width, int height)
		{
			this.x = x;
			this.y = y;
			this.width = width;
			this.height = height;
		}

		public int Left
		{
			get
			{
				return x;
			}
		}

		public int Bottom
		{
			get
			{
				return y;
			}
		}

		public int Right
		{
			get
			{
				return x + width - 1;
			}
		}

		public int Top
		{
			get
			{
				return y + height - 1;
			}
		}

		public bool Intersects(Rectangle r)
		{
			return !(r.Left > this.Right || r.Right < this.Left || r.Top < this.Bottom || r.Bottom > this.Top);
		}

		public bool Contains(int x, int y)
		{
			return x >= Left && x <= Right && y >= Bottom && y <= Top;
		}

		public bool AdjacentTo(Rectangle r)
		{
			return ((Top == r.Bottom || Bottom == r.Top) && Left < r.Right && Right > r.Left) || ((Right == r.Left || Left == r.Right) && Bottom < r.Top && Top > r.Bottom);
		}
	}
}
